package com.blockchain.console.service.common.entity;

import javax.servlet.Servlet;

import com.blockchain.console.servlets.common.Index;
import com.blockchain.console.servlets.common.XlbTj;
import com.blockchain.console.servlets.content.banner.SearchBanner;
import com.blockchain.console.servlets.content.cjwt.QuestionList;
import com.blockchain.console.servlets.content.coin.SearchBxx;
import com.blockchain.console.servlets.content.fltk.UpdateFltk;
import com.blockchain.console.servlets.content.fwzc.UpdateFwzc;
import com.blockchain.console.servlets.content.gggl.SearchGggl;
import com.blockchain.console.servlets.content.ptxg.UpdatePtxg;
import com.blockchain.console.servlets.content.yqlj.SearchYqlj;
import com.blockchain.console.servlets.content.zxgl.SearchZx;
import com.blockchain.console.servlets.financial.bzc.BzcList;
import com.blockchain.console.servlets.financial.bzr.BzrList;
import com.blockchain.console.servlets.financial.cz.CzglList;
import com.blockchain.console.servlets.financial.cz.Qrgl;
import com.blockchain.console.servlets.financial.gd.GdglList;
import com.blockchain.console.servlets.financial.ptzjgl.PtqbList;
import com.blockchain.console.servlets.financial.ptzjgl.PtxlbglList;
import com.blockchain.console.servlets.financial.ptzjgl.PtzjglList;
import com.blockchain.console.servlets.financial.tx.TxglList;
import com.blockchain.console.servlets.financial.zs.Zsgl;
import com.blockchain.console.servlets.system.bank.SearchBank;
import com.blockchain.console.servlets.system.constant.ConstantList;
import com.blockchain.console.servlets.system.constant.ConstantLogList;
import com.blockchain.console.servlets.system.log.SysLogList;
import com.blockchain.console.servlets.system.log.UserLogList;
import com.blockchain.console.servlets.system.role.RoleList;
import com.blockchain.console.servlets.system.sup.SupUserList;
import com.blockchain.console.servlets.system.sys.SysUserList;
import com.blockchain.console.servlets.trading.CjjlList;
import com.blockchain.console.servlets.trading.WtList;
import com.blockchain.console.servlets.trading.jjfq.JyfqList;
import com.blockchain.console.servlets.trading.jysc.JyscList;
import com.blockchain.console.servlets.trading.xlb.XlbList;
import com.blockchain.console.servlets.user.UserGjrz;
import com.blockchain.console.servlets.user.UserList;
import com.blockchain.framework.http.session.Session;

public class ConsoleMenu {

	/**  
	  总览
	 */
	private static ConsoleMenu GL;

	public static ConsoleMenu GL() {
		if (GL != null) {
			return GL;
		}
		Menu[] ms0 = {
				new Menu("信息统计", "XXTJ", Index.class),
				new Menu("虚拟币统计", "XLBTJ", XlbTj.class)		
		};

		SubMenu[] sms = { new SubMenu("信息统计", ms0)
					};
		GL = new ConsoleMenu("概览", "GL", sms);
		return GL;
	}
	
	/**  
	  会员管理
	 */
	private static ConsoleMenu HHGL;

	public static ConsoleMenu HHGL() {
		if (HHGL != null) {
			return HHGL;
		}
		Menu[] ms0 = { new Menu("用户列表", "YHLB", UserList.class),
					   new Menu("高级实名认证", "GJSMRZ", UserGjrz.class)
				};
		SubMenu[] sms = { new SubMenu("用户管理", ms0) };
		HHGL = new ConsoleMenu("用户管理", "HHGL", sms);
		return HHGL;
	}
	
	/**  
	  交易管理
	 */
	private static ConsoleMenu JYGL;

	public static ConsoleMenu JYGL() {
		if (JYGL != null) {
			return JYGL;
		}
		Menu[] ms0 = { 
					   new Menu("虚拟币管理", "XLBGL", XlbList.class),
					   new Menu("分区管理", "FQGL", JyfqList.class),
					   new Menu("市场管理", "SCGL", JyscList.class),
					   new Menu("委托管理", "WTLIST", WtList.class),
					   new Menu("成交记录", "CJJLLIST", CjjlList.class)
					};
		SubMenu[] sms = { new SubMenu("委托管理", ms0) };
		JYGL = new ConsoleMenu("交易管理", "JYGL", sms);
		return JYGL;
	}
	
	/**  
	  财务管理
	 */
	private static ConsoleMenu CWGL;

	public static ConsoleMenu CWGL() {
		if (CWGL != null) {
			return CWGL;
		}
		Menu[] ms0 = { 
					   new Menu("USDZ充值", "RMBCZ", CzglList.class),
					   new Menu("USDZ提现", "TXGL", TxglList.class),
					   new Menu("挂单管理", "GDGL", GdglList.class),
					   new Menu("虚拟币转入", "XLBZR", BzrList.class),
					   new Menu("虚拟币转出", "XLBZC", BzcList.class),
					   new Menu("充值二维码管理", "CZQRGL", Qrgl.class)
					   
					};
		Menu[] ms1 = {  new Menu("平台资金账户", "PTZJGL", PtzjglList.class),
						new Menu("平台虚拟币账户", "PTXLBGL", PtxlbglList.class),
						new Menu("平台虚拟币钱包", "PTXLBQB", PtqbList.class),
						new Menu("赠送管理", "ZSGL", Zsgl.class)
				};
		SubMenu[] sms = { new SubMenu("财务管理", ms0),new SubMenu("平台账户管理", ms1) };
		CWGL = new ConsoleMenu("财务管理", "CWGL", sms);
		return CWGL;
	}
	
	/**
	 * 内容管理
	 */
	private static ConsoleMenu NRGL;

	public static ConsoleMenu NRGL() {
		if (NRGL != null) {
			return NRGL;
		}
		Menu[] ms0 = { new Menu("Banner管理", "BANNER", SearchBanner.class),
				new Menu("公告管理", "GGGL", SearchGggl.class),
				new Menu("资讯管理", "ZXGL", SearchZx.class),
				new Menu("币信息管理", "BXX", SearchBxx.class),
				new Menu("友情链接", "YQLJ", SearchYqlj.class),
				new Menu("帮助中心", "CJWT", QuestionList.class),
				new Menu("平台相关", "PTXG", UpdatePtxg.class),
				new Menu("法律条款", "FLTK", UpdateFltk.class),
				new Menu("服务支持", "FWZC", UpdateFwzc.class)
		};
		SubMenu[] sms = { new SubMenu("内容管理", ms0)};
		NRGL = new ConsoleMenu("内容管理 ", "NRGL", sms);
		return NRGL;
	}
	
	/**
	  系统管理 
	 */
	private static ConsoleMenu XTGL;

	public static ConsoleMenu XTGL() {
		if (XTGL != null) {
			return XTGL;
		}
		Menu[] ms0 = {
				new Menu("管理员管理", "GLYGL", SysUserList.class),
				new Menu("角色管理", "YHZGL", RoleList.class),
				new Menu("控盘账号管理", "KPZHGL", SupUserList.class)
				
		};
		Menu[] ms1 = {
				new Menu("平台常量设置", "PTCLSZ", ConstantList.class),
				new Menu("银行设置", "YHSZ", SearchBank.class)
				};
		Menu[] ms2 = {				
				new Menu("用户日志", "QTDLRZ", UserLogList.class),
				new Menu("后台日志", "HTDLRZ", SysLogList.class),
				new Menu("常量修改日志", "CLXGRZ", ConstantLogList.class)
				};
		SubMenu[] sms = { new SubMenu("后台账号", ms0),new SubMenu("参数设置", ms1),new SubMenu("日志管理", ms2) };
		XTGL = new ConsoleMenu("系统管理", "XTGL", sms);
		return XTGL;
	}

	public ConsoleMenu(String name, String code, SubMenu[] subMenus) {
		this.name = name;
		this.code = code;
		this.subMenus = subMenus;
	}

	/**
	 * 菜单名称
	 */
	public String name;

	/**
	 * 菜单代码
	 */
	public String code;

	/**
	 * 二级菜单代码
	 */
	public SubMenu[] subMenus;

	/**
	 * 取第一个菜单
	 * 
	 * @param blockchainSession
	 * @return
	 */
	public Class<? extends Servlet> getDefaultMenu(Session blockchainSession) {
		for (SubMenu sm : subMenus) {
			for (Menu m : sm.menus) {
				if (blockchainSession.isAccessableResource(m.clazz)) {
					return (Class<? extends Servlet>) m.clazz;
				}
			}
		}
		return null;
	}
}
